package ATBMS.control;

import ATBMS.ucm.UCController;
import ATBMS.ucm.UCLoginUser;
import ATBMS.view.user.UserViewImpl;
import ATBMS.view.login.LoginViewInterface;
import ATBMS.view.useredit.RegisterUserViewImpl;
import java.awt.event.ActionEvent;
import javax.swing.Action;

/**
 * Login Controller
 */
public class LoginControl {

    private LoginViewInterface lv;
    private UCController ucLogin;
    private Action actionAdapter;

    public LoginControl() {
        ucLogin = new UCLoginUser(this);
        actionAdapter = new javax.swing.AbstractAction() {

            public void actionPerformed(ActionEvent e) {
                if (e.getActionCommand().compareTo("Login") == 0) {
                    ucLogin.run();
                } else if (e.getActionCommand().compareTo("Register") == 0) {
                    lv.close();
                    RegisterUserControl ruc = new RegisterUserControl();
                    RegisterUserViewImpl ruv = new RegisterUserViewImpl(MainApp.getApplication().getMainFrame(), ruc);
                    ruc.setUserEditView(ruv);
                    ruv.showView();
                } else if (e.getActionCommand().compareTo("Book Ticket Without Login") == 0) {
                    lv.close();
                    UserControl uc = UserControl.getInstance(null);
                    UserViewImpl uv = new UserViewImpl(MainApp.getApplication(), uc);
                    uc.setUserView(uv);
                    uv.getFrame().setTitle("AirlineTicketBookingManageSystem(NoLogin)");
                    uv.show();
                }

            }
        };
    }

    public LoginViewInterface getLoginView() {
        return lv;
    }

    /**
     * Return a action listener for login view
     * @return Action
     */
    public Action getAction() {
        return actionAdapter;
    }

    /**
     * Set Login View Interface
     */
    public void setLoginView(LoginViewInterface wv) {
        this.lv = wv;
    }
}
